Skip to content

chore: enable CA1515 to prevent unnecessary public types#1698

Open
JamieMagee wants to merge 7 commits intomainfrom
jamiemagee/enable-ca1515
Open

chore: enable CA1515 to prevent unnecessary public types#1698
JamieMagee wants to merge 7 commits intomainfrom
jamiemagee/enable-ca1515

Conversation

@JamieMagee
Copy link
Member

Summary

Enable the CA1515 analyzer rule (Make class internal) in .editorconfig to prevent new unnecessary public types from accumulating in the future.

How it works

CA1515 flags public classes that are not referenced by other assemblies and could safely be internal. Combined with TreatWarningsAsErrors, this will make the build fail if someone adds a new unnecessarily public type.

Note

This rule requires .NET 9+ SDK to enforce. On the current .NET 8 SDK it's a no-op. Once the SDK is upgraded, it will automatically start catching new public types that should be internal.

Stacked on #1696

Part of #455

JamieMagee and others added 6 commits March 5, 2026 20:27
Consolidate all [assembly: InternalsVisibleTo] attributes from scattered
.cs files into their respective .csproj files using MSBuild items.

Add cross-project InternalsVisibleTo entries to enable future phases of
making implementation details internal:
- Detectors → Orchestrator, Tests, TestsUtilities
- Common → Tests, Orchestrator, Detectors, TestsUtilities
- Orchestrator → Tests, CLI entry point, TestsUtilities
- Contracts → Tests, TestsUtilities

Remove scattered attributes from:
- ComponentRecorder.cs
- DependencyGraph.cs
- TelemetryConstants.cs
- IPyPiClient.cs

Part of #455
Change public to internal for deserialization model classes that are
implementation details across multiple detector ecosystems: conan,
pnpm, swiftpm, vcpkg, rust (CargoLock, CargoToml, CargoSbom), poetry,
yarn (Berry contracts, TypeConverter), npm (converters), pip
(PipReportGraphNode, PythonVersion), and uv model classes.

Types exposed through public interfaces/APIs are left public to
maintain build compatibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make ~80 classes internal in the Detectors project:

- Data model/contract classes (ConanLock, PnpmYaml variants, PoetryLock,
  SwiftResolvedFile, VcpkgSBOM, CargoToml/Sbom, YarnBerry types, npm
  converters, PipReportGraphNode, PythonVersion, UvLock/Package, etc.)
- Parser implementations (GoModParser, YarnLockParser, RustCargoLockParser,
  MavenStyleDependencyGraphParserService, PnpmParsingUtilities, etc.)
- Concrete detector classes (NpmComponentDetector, NuGetComponentDetector,
  GoComponentDetector, RustSbomDetector, etc.)
- Linux scanner internals (LinuxScanner, all component factories, filters)
- Service implementations (MavenCommandService, PythonCommandService,
  PyPiClient, PipCommandService, YarnLockFileFactory, etc.)

Kept public (used by downstream consumers):
- All interfaces (IComponentDetector, IMavenCommandService, etc.)
- MvnCliComponentDetector, MavenWithFallbackDetector (used in is-checks)
- PipComponentDetector, SimplePipComponentDetector, PipReportComponentDetector
  (mocked in tests by component-detection-internal)

Updated test classes to work with internal types via InternalsVisibleTo.

Part of #455
Make ~50 classes internal in the Common project:

- Telemetry records (~34 concrete classes): NuGetProjectAssetsTelemetryRecord,
  PyPiCacheTelemetryRecord, LinuxScannerTelemetryRecord, etc.
  Kept BaseDetectionTelemetryRecord public for external subclassing.
- Utility classes: Column, TabularStringFormat, ComponentComparer,
  DependencyScopeComparer, DirectoryItemFacade(Optimized)
- Docker reference exceptions (11 classes)
- Concrete service implementations: CommandLineInvocationService,
  EnvironmentVariableService, PathUtilityService, FileUtilityService,
  DirectoryUtilityService, DockerService, ConsoleWritingService,
  SafeFileEnumerableFactory, ComponentStreamEnumerableFactory,
  FastDirectoryWalkerFactory

Kept public: FileWritingService, ComponentStream, LazyComponentStream,
ComponentRecorder, CommandLineInvocationResult, CommandLineTelemetryService,
BaseDetectionTelemetryRecord, and all interfaces.

Part of #455
Make 8 classes internal in the Orchestrator project:

- Converter classes: CommaDelimitedConverter, KeyValueDelimitedConverter,
  SemicolonDelimitedConverter
- CLI helpers: ArgumentHelper, IArgumentHelper
- Concrete service implementations: DetectorProcessingService,
  DetectorRestrictionService, DefaultGraphTranslationService

Kept public: ServiceCollectionExtensions, ScanExecutionService, ScanCommand,
ScanSettings, LoggingEnricher, DetectorRestrictions, all experiment types,
all service interfaces, DetectorRunResult, DetectorProcessingResult.

Part of #455
Enable the CA1515 analyzer rule ("Make class internal") in
.editorconfig to prevent new unnecessary public types from
accumulating in the future.

This rule requires .NET 9+ SDK to enforce. Once the SDK is
upgraded, any new public class that could be internal will
produce a build warning.

Part of #455
@JamieMagee JamieMagee requested a review from a team as a code owner March 6, 2026 21:14
@JamieMagee JamieMagee requested review from ByAgenT and removed request for a team March 6, 2026 21:14
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.8%. Comparing base (ceb93da) to head (94e0615).

Additional details and impacted files
@@                           Coverage Diff                            @@
##           jamiemagee/access-modifiers-orchestrator   #1698   +/-   ##
========================================================================
  Coverage                                      90.8%   90.8%           
========================================================================
  Files                                           453     453           
  Lines                                         40344   40344           
  Branches                                       2447    2447           
========================================================================
  Hits                                          36653   36653           
  Misses                                         3191    3191           
  Partials                                        500     500           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JamieMagee JamieMagee force-pushed the jamiemagee/access-modifiers-orchestrator branch from ceb93da to 355692a Compare March 6, 2026 22:20
Base automatically changed from jamiemagee/access-modifiers-orchestrator to main March 6, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant